package com.demo.result;

/**
 * @author yl
 * @description
 * @date 2020/11/17 14:03
 */
public enum  ApiCode {

    /**
     * 操作成功
     **/
    SUCCESS(0, "成功"),
    /**
     * 操作失败
     **/
    FAIL(500, "失败"),
    ;

    private final int code;
    private final String message;

    ApiCode(final int code, final String message) {
        this.code = code;
        this.message = message;
    }

    public static ApiCode getApiCode(int code) {
        ApiCode[] ecs = ApiCode.values();
        for (ApiCode ec : ecs) {
            if (ec.getCode() == code) {
                return ec;
            }
        }
        return SUCCESS;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
